package com.heima.admin.listener;

import com.alibaba.fastjson.JSON;
import com.heima.admin.service.WemediaNewsAutoScanService;
import com.heima.common.exception.CustException;
import com.heima.model.common.constants.NewsAutoScanConstants;
import com.heima.model.common.enums.AppHttpCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@Slf4j
public class WemediaNewsAutoListener {

    @Autowired
    WemediaNewsAutoScanService wemediaNewsAutoScanService;

    /**
     * 发布文章就自动审核消息
     * @param message
     */
    @KafkaListener(topics = NewsAutoScanConstants.WM_NEWS_AUTO_SCAN_TOPIC)
    public void recevieMessage(String message) {
        if (StringUtils.isNotBlank(message)) {
            Map<String,Integer> map = JSON.parseObject(message, Map.class);
            Integer wmNewsId = map.get("wmNewsId");
            if (wmNewsId != null) {
                wemediaNewsAutoScanService.autoScanByMediaNewsId((wmNewsId));
            }
        }
        log.info("自动审核消息完成");
    }

}